#include<bits/stdc++.h>
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline unsigned long long rd() {//读入一个 64 位无符号整数
	unsigned long long x=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch)) x=x*10+(ch^48),ch=gc();
	return x;
}
const int N = 5e6+20,MOD = 5000011;
struct node{
    unsigned long long key,val;
    int nxt;
} nds[N];
int pcnt;
int pre[MOD];
uint64_t splitmix64(uint64_t x) {
    uint64_t z = (x += 0x9e3779b97f4a7c15);
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
    z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
    return z ^ (z >> 31);
}
inline int mhash(unsigned long long v){
    
    return splitmix64(v)%MOD;
}
unsigned long long query(unsigned long long x){
    int p = mhash(x);
    for(int vi = pre[p];vi;vi = nds[vi].nxt){
        if(nds[vi].key == x){
            return nds[vi].val;
        }
    }
    return 0;
}
void update(unsigned long long x,unsigned long long y){
    int p = mhash(x);
    int lst = 0;
    for(int vi = pre[p];vi;vi = nds[vi].nxt){
        if(nds[vi].key == x){
            nds[vi].val = y;
            return;
        }
        lst = vi;
    }
    int now = ++pcnt;
    if(lst){
        nds[lst].nxt = now;
    }else{
        pre[p] = now;
    }
    nds[now] = {x,y,0};
}

int main(){
    int n = rd();
    unsigned long long ans = 0;
    for(int i = 1;i<=n;i++){
        unsigned long long x = rd(),y = rd();
        ans += query(x)*i;
        update(x,y);
    }
    cout<<ans<<'\n';
}